package behaviour;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import maze.Coordinate;
import maze.Direction;
import maze.Location;
import maze.Maze;

public class Explorer implements Strategy {
	
	private Coordinate currentCoordinate;
	private ArrayList<Direction> path = new ArrayList<Direction>();
	private Maze maze;
	public Explorer (Maze maze){
		
		this.maze=maze;
	}
	@Override
	public Direction nextDirection(Location loc) {
		Direction ret;
		
		//maze.draw(maze.getCoordinateOfLocation(loc).getX(),maze.getCoordinateOfLocation(loc).getY());
		
		if(path.size() == 0)
		{
			currentCoordinate=maze.getCoordinateOfLocation(loc);
			//System.out.println(currentCoordinate);
			Coordinate[] closestUnkown = maze.pathToClosestUnknown(currentCoordinate.getX(), currentCoordinate.getY(), true);
			if(closestUnkown == null)//maze volledig verkend
			{
				return null;
			}
			for(int i=0; i<closestUnkown.length; i++)
			{
				path.add(currentCoordinate.getDirectionOfCoordinate(closestUnkown[i]));
				currentCoordinate = closestUnkown[i];
			}				
		}
		
		ret = path.get(0);
		path.remove(0);
		
		return ret;
	}
	
}
